<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        维保合同管理添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">

</head>
<style>

</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>


<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <h3><b>基本信息</b></h3> <br>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同性质</label>
                    <div class="layui-input-block">
                        <select lay-verify="required" name="natureOfContract">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同名称</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="contractName"
                               v-model="maintenanceContract.contractName"
                               lay-verify="required" placeholder="合同名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>合同编号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="contractNo"
                               v-model="maintenanceContract.contractNo"
                               placeholder="合同编号" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同类型</label>
                    <div class="layui-input-block">
                        <select lay-verify="required" name="typeOfContract">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>项目名称</label>
                    <div class="layui-input-inline">
                        <select lay-verify="required" name="entryName"  lay-search="">
                            <option value="">---</option>
                        </select>
                        <!--                        <input  autocomplete="off"  type="text" name="entryName"-->
                        <!--                               v-model="maintenanceContract.entryName"-->
                        <!--                               lay-verify="required" placeholder="项目名称" class="layui-input">-->
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>甲方单位</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="partyA"
                               v-model="maintenanceContract.partyA"
                               lay-verify="required" placeholder="甲方单位" class="layui-input">
                    </div>
                </div>



                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>甲方负责人</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyA"
                               v-model="maintenanceContract.personInChargeOfPartyA"
                               placeholder="甲方负责人" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>负责人员</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="responsiblePerson"
                               v-model="maintenanceContract.responsiblePerson"
                               lay-verify="required" placeholder="负责人员" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同时长</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="contractDuration"
                               v-model="maintenanceContract.contractDuration"
                               lay-verify="required" placeholder="单位/个月" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同总额</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="totalContractAmount"
                               v-model="maintenanceContract.totalContractAmount"
                               lay-verify="required" placeholder="合同总额" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>开始时间</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="startTime"
                               v-model="maintenanceContract.startTime" id="startTime"
                               lay-verify="required" placeholder="开始时间" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>结束时间</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="endTime" id="endTime"
                               v-model="maintenanceContract.endTime"
                               lay-verify="required" placeholder="结束时间" class="layui-input">
                    </div>
                </div>
                <h3><b>附加信息</b></h3> <br>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>电梯台数</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="numberOfElevators"
                               v-model="maintenanceContract.numberOfElevators"
                               lay-verify="required" placeholder="电梯台数" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>抢修电话</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="repairPhone"
                               v-model="maintenanceContract.repairPhone"
                               placeholder="抢修电话" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>是否带票</label>
                    <div class="layui-input-inline">
                        <select name="doYouHaveATicketWithYou">
                            <option selected value="否">否</option>
                            <option value="是">是</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>是否驻场</label>
                    <div class="layui-input-inline">
                        <select name="onSiteOrNot">
                            <option selected value="否">否</option>
                            <option value="是">是</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>电梯年检费</label>
                    <div class="layui-input-inline">
                        <select name="elevatorAnnualInspectionFee">
                            <option selected value="不含">不含</option>
                            <option value="包含">包含</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>限速器校验费</label>
                    <div class="layui-input-inline">
                        <select name="speedLimiterCalibrationFee">
                            <option selected value="不含">不含</option>
                            <option value="包含">包含</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>结算间隔</label>
                    <div class="layui-input-inline">
                        <select name="settlementInterval">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>支付方式</label>
                    <div class="layui-input-inline">
                        <select name="payType">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>保养间隔</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="maintenanceInterval"
                               v-model="maintenanceContract.maintenanceInterval"
                               placeholder="保养间隔/天" class="layui-input">
                        </select>
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>保养方式</label>
                    <div class="layui-input-inline">
                        <select lay-verify="required" name="maintenanceMode">
                            <option value="">---</option>

                        </select>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>配件约定</label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="text" name="accessoriesAgreement"
                               v-model="maintenanceContract.accessoriesAgreement"
                               placeholder="金额/元" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>驻场人员</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="fieldPersonnel"
                               v-model="maintenanceContract.fieldPersonnel"
                               placeholder="驻场人员" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>适用电梯</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="applicableElevator"
                               v-model="maintenanceContract.applicableElevator"
                               placeholder="适用电梯" class="layui-input">
                    </div>
                </div>

                <div class=" layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>备注</label>
                    <div class="layui-input-block">
                        <textarea name="remarks" placeholder="请输入内容" v-model="maintenanceContract.remarks"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>


                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <div style="height:100px;"></div>
            </div>

        </div>

    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");


    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#startTime', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.maintenanceContract.startTime = value
                }
            });
            laydate.render({
                elem: '#endTime', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.maintenanceContract.endTime = value
                }
            });


            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = vm.maintenanceContract.id;
                    vm.maintenanceContract.id == null ? form.operationType = 'add' : form.operationType = 'edit';

                    let request = {
                        url: 'maintenanceContract/addMaintenanceContract',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();


                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });
        });


    const vm = new Vue({
        el: "#app",
        data: {
            maintenanceContract: {
                id: null,
                natureOfContract: null,
                contractName: null,
                contractNo: null,
                typeOfContract: null,
                partyA: null,
                entryName: null,
                personInChargeOfPartyA: null,
                responsiblePerson: null,
                contractDuration: null,
                totalContractAmount: null,
                startTime: null,
                endTime: null,
                numberOfElevators: null,
                repairPhone: null,
                doYouHaveATicketWithYou: null,
                onSiteOrNot: null,
                elevatorAnnualInspectionFee: null,
                speedLimiterCalibrationFee: null,
                settlementInterval: null,
                payType: null,
                maintenanceInterval: null,
                maintenanceMode: null,
                accessoriesAgreement: null,
                fieldPersonnel: null,
                applicableElevator: null,
                remarks: null,
            }
        },
        created() {
            if (recordId) {
                let request = {
                    url: 'maintenanceContract/findMaintenanceContract',
                    data: {
                        userId: $userId,
                        recordId: recordId
                    },
                    method: "POST"
                };
                sendRequest(request, (res) => {
                    // console.log(res);
                    this.maintenanceContract = res.data;
                })

            }
        },
        methods: {},


    });
    setTimeout(() => {
        //修改状态
        let form = layui.form;


        //合同性质
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'NATURE_OF_CONTRACT'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=natureOfContract]").append(opt);
            });

            $("select[name=natureOfContract]").val(vm.maintenanceContract.natureOfContract);

            form.render('select');

        });
        //合同类型
        let request1 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'TYPE_OF_CONTRACT'
            },
            method: "POST",
        };
        sendRequest(request1, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=typeOfContract]").append(opt);
            });

            $("select[name=typeOfContract]").val(vm.maintenanceContract.typeOfContract);

            form.render('select');

        });
        //结算间隔
        let request2 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'SETTLEMENT_INTERVAL'
            },
            method: "POST",
        };
        sendRequest(request2, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=settlementInterval]").append(opt);
            });

            $("select[name=settlementInterval]").val(vm.maintenanceContract.settlementInterval);

            form.render('select');

        });
        //保养方式
        let request3 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'MAINTENANCE_MODE'
            },
            method: "POST",
        };
        sendRequest(request3, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=maintenanceMode]").append(opt);
            });

            $("select[name=maintenanceMode]").val(vm.maintenanceContract.maintenanceMode);

            form.render('select');

        });
        //支付方式
        let request4 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'REVENUE_AND_EXPENDITURE_CHANNEL'
            },
            method: "POST",
        };
        sendRequest(request4, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=payType]").append(opt);
            });

            $("select[name=payType]").val(vm.maintenanceContract.payType);

            form.render('select');

        });


        //项目名称
        let request5 = {
            url: 'maintenance/project/findAll',
            data: {
                userId: $userId,
            },
            method: "GET",
        };
        sendRequest(request5, (res) => {
            console.log(res);
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item.name + ">" + item.name + "</option>");
                $("select[name=entryName]").append(opt);
            });

            $("select[name=entryName]").val(vm.maintenanceContract.entryName);

            form.render('select');

        });



        $("select[name=entryName]").val(vm.maintenanceContract.entryName);
        $("select[name=doYouHaveATicketWithYou]").val(vm.maintenanceContract.doYouHaveATicketWithYou);
        $("select[name=onSiteOrNot]").val(vm.maintenanceContract.onSiteOrNot);
        $("select[name=elevatorAnnualInspectionFee]").val(vm.maintenanceContract.elevatorAnnualInspectionFee);
        $("select[name=speedLimiterCalibrationFee]").val(vm.maintenanceContract.speedLimiterCalibrationFee);

        form.render('select');


    }, 500)
</script>

</body>

</html>
